const http = require('http');
const fs = require('fs');

http.createServer( (req, res) => {
  const name = require('url').parse(req.url, true).query.name;

  if( name === undefined) name = 'RNG-GALA';
  if(name === 'gala'){
    const file = 'gala.png';
    fs.stat( file, (err, stat) => {
      if(err){
        console.log('err:', err)
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('抱歉, 您的外挂正在路上....');
      }else {
        const img = fs.readFileSync(file);
        res.contentType = 'image/png';
        res.contentLength = stat.size;
        res.end(img, 'binary'); 
      }
    })
  }else{
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('hellp' + name + '\n');
  }
}).listen(3000)

console.log('runing.....')